#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

int main(int argc, char *argv[])
{
    SDL_Surface *ecran = NULL, *mega1 = NULL , *imageDeFond = NULL   ;
    SDL_Rect posfond , positionmega1 ;
    int continuer = 1 ;
    int i = 10000 ;
    positionmega1.x = 0 ;
    positionmega1.y = 100 ;


    imageDeFond->w = 600;
    imageDeFond->h = 400 ;
    posfond.x = 0 ;
    posfond.y= 0 ;


    SDL_Event event;

    SDL_Init(SDL_INIT_VIDEO);

    ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
    SDL_WM_SetCaption("déplacement", NULL);

    imageDeFond = IMG_Load("fond.jpg");


    mega1 = IMG_Load("1.png");



    SDL_EnableKeyRepeat(5,5);
    while (continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
        case SDL_QUIT:
            continuer = 0;
            break;
        case SDL_KEYDOWN:
            switch(event.key.keysym.sym)
            {

            case SDLK_RIGHT:
                positionmega1.x++;
                i++ ;

                if (i%6==0)
                    mega1 = IMG_Load("1.png");


                if (i%6==1)
                    mega1 = IMG_Load("2.png");


                if (i%6==2)
                    mega1 = IMG_Load("3.png");

                if (i%6==3)
                    mega1 = IMG_Load("4.png");


                if (i%6==4)
                    mega1 = IMG_Load("5.png");


                if (i%6==5)
                    mega1 = IMG_Load("6.png");

                break;
//                    case SDLK_LEFT:
                //                      positionmega.x--;
                //                    break;
            }
            break;
        }


        SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
        SDL_BlitSurface(imageDeFond, NULL, ecran, &posfond);
        SDL_BlitSurface(mega1, NULL, ecran, &positionmega1);


        SDL_Flip(ecran);
    }
    SDL_FreeSurface(mega1);

    SDL_FreeSurface(imageDeFond);
    SDL_Quit();
    return EXIT_SUCCESS;
}
